home *** CD-ROM | disk | FTP | other *** search
/ Acorn User: China / Acorn User China CD-ROM (UK) (Disc A) / Acorn User China CD-ROM (UK) (Disc A).bin / DEMON / DEVELOPER / HYPERMAIL.ARC / !hypermail_c_hypermail < prev    next >
Encoding:
Text File  |  1996-01-24  |  6.2 KB  |  188 lines

  1. /*
  2. ** Copyright (C) 1994, Enterprise Integration Technologies Corp.        
  3. ** All Rights Reserved.
  4. ** Kevin Hughes, kevinh@eit.com 
  5. ** 8/2/94
  6. */
  7.  
  8. #define MAIN_FILE
  9. #include "hypermail.h"
  10.  
  11. int main(argc, argv)
  12.      int argc;
  13.      char **argv;
  14. {
  15.         extern char *optarg;
  16.         extern int optind;
  17.         int i, overwrite, use_stdin, use_mbox, increment;
  18.         char mbox[MAXLINE], label[MAXLINE], dir[MAXLINE],
  19.                 archives[MAXLINE], about[MAXLINE], configfile[MAXLINE],
  20.                 defaultindex[MAXLINE];
  21.  
  22. /* Load the hard-wired defaults, then the environment variables.
  23. */
  24.         strcpy(mbox, MBOX);
  25.         if (getenv("HM_MBOX") != NULL)
  26.                 strcpy(mbox, getenv("HM_MBOX"));
  27.         strcpy(archives, ARCHIVES);
  28.         if (getenv("HM_ARCHIVES") != NULL)
  29.                 strcpy(archives, getenv("HM_ARCHIVES"));
  30.         strcpy(about, ABOUT);
  31.         if (getenv("HM_ABOUT") != NULL)
  32.                 strcpy(about, getenv("HM_ABOUT"));
  33.         strcpy(label, LABEL);
  34.         if (getenv("HM_LABEL") != NULL)
  35.                 strcpy(label, getenv("HM_LABEL"));
  36.         strcpy(dir, DIR);
  37.         if (getenv("HM_DIR") != NULL)
  38.                 strcpy(dir, getenv("HM_DIR"));
  39.         strcpy(defaultindex, DEFAULTINDEX);
  40.         if (getenv("HM_DEFAULTINDEX") != NULL)
  41.                 strcpy(defaultindex, getenv("HM_DEFAULTINDEX"));
  42.  
  43.         showprogress = PROGRESS;
  44.         if (getenv("HM_PROGRESS") != NULL)
  45.                 showprogress = atoi(getenv("HM_PROGRESS"));
  46.         overwrite = OVERWRITE;
  47.         if (getenv("HM_OVERWRITE") != NULL)
  48.                 overwrite = atoi(getenv("HM_OVERWRITE"));
  49.         increment = INCREMENT;
  50.         if (getenv("HM_INCREMENT") != NULL)
  51.                 increment = atoi(getenv("HM_INCREMENT"));
  52.         reverse = REVERSE;
  53.         if (getenv("HM_REVERSE") != NULL)
  54.                 reverse = atoi(getenv("HM_REVERSE"));
  55.         showheaders = SHOWHEADERS;
  56.         if (getenv("HM_SHOWHEADERS") != NULL)
  57.                 showheaders = atoi(getenv("HM_SHOWHEADERS"));
  58.         showhtml = SHOWHTML;
  59.         if (getenv("HM_SHOWHTML") != NULL)
  60.                 showhtml = atoi(getenv("HM_SHOWHTML"));
  61.         thrdlevels = THRDLEVELS;
  62.         if (getenv("HM_THRDLEVELS") != NULL)
  63.                 thrdlevels = atoi(getenv("HM_THRDLEVELS"));
  64.         dirmode = DIRMODE;
  65.         if (getenv("HM_DIRMODE") != NULL)
  66.                 dirmode = strtol(getenv("HM_DIRMODE"), (char **) NULL, 0);
  67.         filemode = FILEMODE;
  68.         if (getenv("HM_FILEMODE") != NULL)
  69.                 filemode = strtol(getenv("HM_FILEMODE"), (char **) NULL, 0);
  70.  
  71.         strcpy(configfile, CONFIGFILE);
  72.         if (getenv("HM_CONFIGFILE") != NULL)
  73.                 strcpy(configfile, getenv("HM_CONFIGFILE"));
  74.  
  75.         if (!strcmp(mbox, "NONE"))
  76.                 use_stdin = 1;
  77.         else
  78.                 use_stdin = 0;
  79.  
  80. /* ...then use the command-line options...
  81. */
  82.  
  83.         use_mbox = 0;
  84.         firstdatenum = lastdatenum = 0;
  85.         while ((i = (int) getopt(argc, argv, "?zhixupm:l:d:a:b:c:")) != -1)
  86.                 if ((char) i == 'm') {
  87.                         strcpy(mbox, optarg);
  88.                         use_mbox = 1;
  89.                 }
  90.                 else if ((char) i == 'a')
  91.                         strcpy(archives, optarg);
  92.                 else if ((char) i == 'b')
  93.                         strcpy(about, optarg);
  94.                 else if ((char) i == 'l')
  95.                         strcpy(label, optarg);
  96.                 else if ((char) i == 'd')
  97.                         strcpy(dir, optarg);
  98.                 else if ((char) i == 'c')
  99.                         strcpy(configfile, optarg);
  100.                 else if ((char) i == 'x')
  101.                         overwrite = 1;
  102.                 else if ((char) i == 'i')
  103.                         use_stdin = 1;
  104.                 else if ((char) i == 'p')
  105.                         showprogress = 1;
  106.                 else if ((char) i == 'u')
  107.                         increment = 1;
  108.                 else if ((char) i == 'z' || (char) i == 'h' ||
  109.                 (char) i == '?')
  110.                         usage();
  111.                 else
  112.                         usage();
  113.  
  114. /* ...then read the configuration file.
  115. */
  116.  
  117.         readconfigs(configfile, mbox, label, dir, archives, about, &overwrite,
  118.                 &increment, defaultindex);
  119.  
  120. /* Default names for directories and labels need to be figured out.
  121. */
  122.  
  123.         if (use_stdin && !strcmp(dir, "NONE"))
  124.                 strcpy(dir, DIRNAME);
  125.         if (!strcmp(dir, "NONE"))
  126.  
  127. #ifdef RISCOS
  128. /* This needs sorting. I can't remember what it tries to do... */
  129.                 strcpy(dir, (strrchr(mbox, '.')) ? (char *) strrchr(mbox, '.')+ 1 : mbox);
  130.         if (!strcmp(label, "NONE"))
  131.  
  132.                 strcpy(label, (strrchr(mbox, '.')) ? (char *) strrchr(mbox, '.')
  133.                 + 1 : mbox);
  134. #else
  135.                 strcpy(dir, (strrchr(mbox, '/')) ? (char *) strrchr(mbox, '/')
  136.                 strcpy(label, (strrchr(mbox, '/')) ? (char *) strrchr(mbox, '/')
  137. #endif
  138.  
  139. /* Which index file will be called "index.html"?
  140. */
  141.  
  142.  
  143.         strcpy(datename, (!strcmp(defaultindex, "date")) ? INDEXNAME :
  144.         DATENAME);
  145.  
  146.         strcpy(thrdname, (!strcmp(defaultindex, "thread")) ? INDEXNAME :
  147.         THRDNAME);
  148.  
  149.         strcpy(subjname, (!strcmp(defaultindex, "subject")) ? INDEXNAME :
  150.         SUBJNAME);
  151.  
  152.         strcpy(authname, (!strcmp(defaultindex, "author")) ? INDEXNAME :
  153.         AUTHNAME);
  154.  
  155.  
  156.         if (use_mbox && use_stdin)
  157.                 progerr("Can't read from file and stdin at once.");
  158.  
  159.         gettimezone();
  160.         getthisyear();
  161.         if (increment) {
  162.                 loadoldheaders(dir);
  163.                 loadheaders(mbox, use_stdin, 1);
  164.                 checkdir(dir);
  165.                 writearticles(dir, label, overwrite, bignum);
  166.                 fixnextheader(dir, bignum - 1);
  167. #ifdef SHOWREPLIES
  168.                 fixreplyheader(dir, bignum);
  169. #endif
  170.                 fixthreadheader(dir, bignum);
  171.         }
  172.         else {
  173.                 loadheaders(mbox, use_stdin, 0);
  174.                 checkdir(dir);
  175.                 writearticles(dir, label, overwrite, 0);
  176.         }
  177.  
  178. /* Always write the index files
  179. */
  180.  
  181.         writedates(dir, label, archives, about);
  182.         writethreads(dir, label, archives, about);
  183.         writesubjects(dir, label, archives, about);
  184.         writeauthors(dir, label, archives, about);
  185.  
  186.         exit(0);
  187. }
  188.